
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 07/24/2011 11:30:27
-- Generated from EDMX file: C:\Users\Alexis\Documents\Visual Studio 2010\Projects\GRC_TPE\GRC_TPE\GRC_TPE_WebApp\Model\Model_GRC_TPE.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [GRCTPEDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_ClientContact]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContactSet] DROP CONSTRAINT [FK_ClientContact];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientBusiness]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BusinessSet] DROP CONSTRAINT [FK_ClientBusiness];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientCommunication]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommunicationSet] DROP CONSTRAINT [FK_ClientCommunication];
GO
IF OBJECT_ID(N'[dbo].[FK_UserCommunication]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CommunicationSet] DROP CONSTRAINT [FK_UserCommunication];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[ClientSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ClientSet];
GO
IF OBJECT_ID(N'[dbo].[CommunicationSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CommunicationSet];
GO
IF OBJECT_ID(N'[dbo].[ContactSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContactSet];
GO
IF OBJECT_ID(N'[dbo].[BusinessSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BusinessSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Lastname] nvarchar(max)  NOT NULL,
    [Firstname] nvarchar(max)  NOT NULL,
    [Username] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ClientSet'
CREATE TABLE [dbo].[ClientSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Activity] nvarchar(max)  NOT NULL,
    [Adresse] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CommunicationSet'
CREATE TABLE [dbo].[CommunicationSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Date] datetime  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [ClientId] int  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'ContactSet'
CREATE TABLE [dbo].[ContactSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Function] nvarchar(max)  NOT NULL,
    [Firstname] nvarchar(max)  NOT NULL,
    [Lastname] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NULL,
    [ClientId] int  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'BusinessSet'
CREATE TABLE [dbo].[BusinessSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [State] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [ClientId] int  NOT NULL,
    [Amount] decimal(18,0)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ClientSet'
ALTER TABLE [dbo].[ClientSet]
ADD CONSTRAINT [PK_ClientSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CommunicationSet'
ALTER TABLE [dbo].[CommunicationSet]
ADD CONSTRAINT [PK_CommunicationSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ContactSet'
ALTER TABLE [dbo].[ContactSet]
ADD CONSTRAINT [PK_ContactSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'BusinessSet'
ALTER TABLE [dbo].[BusinessSet]
ADD CONSTRAINT [PK_BusinessSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ClientId] in table 'ContactSet'
ALTER TABLE [dbo].[ContactSet]
ADD CONSTRAINT [FK_ClientContact]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[ClientSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientContact'
CREATE INDEX [IX_FK_ClientContact]
ON [dbo].[ContactSet]
    ([ClientId]);
GO

-- Creating foreign key on [ClientId] in table 'BusinessSet'
ALTER TABLE [dbo].[BusinessSet]
ADD CONSTRAINT [FK_ClientBusiness]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[ClientSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientBusiness'
CREATE INDEX [IX_FK_ClientBusiness]
ON [dbo].[BusinessSet]
    ([ClientId]);
GO

-- Creating foreign key on [ClientId] in table 'CommunicationSet'
ALTER TABLE [dbo].[CommunicationSet]
ADD CONSTRAINT [FK_ClientCommunication]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[ClientSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientCommunication'
CREATE INDEX [IX_FK_ClientCommunication]
ON [dbo].[CommunicationSet]
    ([ClientId]);
GO

-- Creating foreign key on [UserId] in table 'CommunicationSet'
ALTER TABLE [dbo].[CommunicationSet]
ADD CONSTRAINT [FK_UserCommunication]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserCommunication'
CREATE INDEX [IX_FK_UserCommunication]
ON [dbo].[CommunicationSet]
    ([UserId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------